<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="名称">
              <a-input placeholder="输入名称模糊查询" v-model="queryParam.topicName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核状态">
              <a-select allowClear placeholder="输选择审核状态" v-model="queryParam.checkResult">
                <a-select-option :value="-1">全部</a-select-option>
                <a-select-option :value="0">待审核</a-select-option>
                <a-select-option :value="1">已通过</a-select-option>
                <a-select-option :value="2">未通过</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="部门名称">
              <j-tree-select
                v-model="queryParam.departId"
                placeholder="请选择部门"
                dict="sys_depart,depart_name,id"
                pidField="parent_id">
              </j-tree-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="9" :md="10" :sm="24">
            <a-form-item>
              <a-button-group style="margin-bottom: 24px;">
                <a-button :type="queryParam.timeType == 0?'primary':''" @click="timeTypeChange(0)">全部</a-button>
                <a-button :type="queryParam.timeType == 1?'primary':''" @click="timeTypeChange(1)">当天</a-button>
                <a-button :type="queryParam.timeType == 2?'primary':''" @click="timeTypeChange(2)">本周</a-button>
                <a-button :type="queryParam.timeType == 3?'primary':''" @click="timeTypeChange(3)">本月</a-button>
              </a-button-group>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload"
                          style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <div v-bind="fullScreenParentProps">
        <a-icon class="full-screen-icon" type="fullscreen" @click="()=>fullCoder=!fullCoder"/>
        <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
                 :pagination="ipagination" :loading="loading">
          <span slot="action" slot-scope="text, record">
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical"/>
            <a @click="showAudit(record,1)" v-if="record.checkResult == 0 || record.checkResult == 2 ">通过</a>
            <a-divider type="vertical" v-if="record.checkResult == 0"/>
            <a @click="showAudit(record,2)" v-if="record.checkResult == 0 || record.checkResult == 1 ">不通过</a>
            <a-divider type="vertical" v-if="record.checkResult == 1"/>
            <template v-has="'task:create'">
               <a @click="handleCreataTask(record)" style="margin-left:5px" v-if="record.checkResult == 1">创建任务</a>
            </template>
          </span>
        </a-table>
      </div>
    </div>
    <tasTopicInfo-modal ref="modalForm" @ok="modalFormOk"></tasTopicInfo-modal>
    <task-create ref="taskCreate"></task-create>
    <a-modal
      title="审核说明"
      width="400px"
      :confirmLoading="confirmLoading"
      :visible="showAuditModal"
      @cancel="closeAuditModal"
      @ok="handlePass">
      <a-textarea v-model="auditData.checkContent" placeholder="请输入审核说明"></a-textarea>
    </a-modal>
  </a-card>
</template>

<script>
  import TasTopicInfoModal from './modules/TasTopicInfoModal'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {postAction} from '@/api/manage'
  import {findTopicCheckResultName} from "@/utils/xinkeUtil";
  import TaskCreate from "../task/TaskCreate";

  export default {
    name: "TopicAudit",
    mixins: [JeecgListMixin],
    components: {TaskCreate, TasTopicInfoModal},
    computed: {
      fullScreenParentProps() {
        let props = {
          class: ['full-screen-parent', this.fullCoder ? 'full-screen' : ''],
          style: {}
        }
        if (this.fullCoder) {
          props.style['z-index'] = this.zIndex
        }
        return props
      },
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    data() {
      return {
        columns: [{
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
          {
            title: '部门名称',
            align: "center",
            dataIndex: 'departName'
          },
          {
            title: '作者',
            align: "center",
            dataIndex: 'author'
          },
          {
            title: '创建日期',
            align: "center",
            dataIndex: 'createTime'
          },
          {
            title: '选题名称',
            align: "center",
            dataIndex: 'topicName'
          },
          {
            title: '选题描述',
            align: "center",
            dataIndex: 'topicDesc'
          },
          {
            title: '审核结果',
            align: "center",
            dataIndex: 'checkResult',
            customRender: function (t) {
              return findTopicCheckResultName(t)
            }
          },
          {
            title: '备注',
            align: "center",
            dataIndex: 'remark'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            scopedSlots: {
              customRender: 'action'
            },
          }
        ],
        url: {
          list: "task/innerTopic/innerTopicList",
          pass: "task/innerTopic/reviewInnerTopic"
        },
        fullScreen: false,
        fullCoder: false,
        queryParam: {
          timeType: 0,
          topicName: "",
          checkResult: -1
        },
        showAuditModal: false,
        auditData: {
          checkContent: ''
        },
        confirmLoading:false
      }
    },
    methods: {
      searchReset() {
        this.queryParam = {timeType: 0, checkResult: -1};
        this.loadData(1);
      },
      timeTypeChange(timeType) {
        this.queryParam.timeType = timeType;
        this.loadData(1);
      },
      handlePass() {
        this.confirmLoading = true;
        postAction(this.url.pass, this.auditData).then((res) => {
          if (res.success) {
            this.$message.success(res.message);
            this.closeAuditModal();
            this.loadData(1);
          } else {
            this.$message.warning(res.message);
          }
        }).finally(()=>{
          this.confirmLoading = false
        })
      },
      handleCreataTask(record) {
        this.$refs.taskCreate.show({topic: record})
      },
      showAudit(record, checkResult) {
        this.auditData.id = record.id;
        this.auditData.checkResult = checkResult;
        this.showAuditModal = true;
      },
      closeAuditModal() {
        this.showAuditModal = false;
        this.auditData.checkContent = '';
      }
    }
  }
</script>

<style scoped>
  @import '~@assets/less/common.less';

  .full-screen-parent.full-screen {
    z-index: 999
  }

</style>
